package com.base.util.javautils.app;

import android.app.Application;
import android.content.Context;
import android.support.annotation.NonNull;

import com.base.util.javautils.log.ILogPrinter;
import com.base.util.javautils.log.LogUtil;
import com.base.util.javautils.xutil.XUtilAdapter;

/**
 * @author gj
 */
public class AppCore extends Application {

    public static AppCore cast(@NonNull Context ctx) {
        if (ctx instanceof AppCore) {
            return (AppCore) ctx;
        }
        return (AppCore) ctx.getApplicationContext();
    }

    protected ILogPrinter mLogPrinter = LogUtil.createLogPrinter(getClass());

    private AbstractActivity mCurrentActivity = null;

    public AbstractActivity getCurrentActivity() {
        return mCurrentActivity;
    }

    public void setCurrentActivity(@NonNull AbstractActivity currentActivity) {
        mCurrentActivity = currentActivity;
    }

    private void initUtil() {
        mLogPrinter.flag();
        // init xUtil
        XUtilAdapter.initXUtil(this);
    }

    @Override
    public void onCreate() {
        super.onCreate();
        mLogPrinter.flag();
        initUtil();
    }


    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mLogPrinter.flag();
    }

}
